package com.xintonghua.bussiness.ui.fragment;

import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.xintonghua.base.BuildConfig;
import com.xintonghua.base.ui.BaseFragment;
import com.xintonghua.base.ui.ImageActivity;
import com.xintonghua.base.utils.MyUtils;
import com.xintonghua.bussiness.R;
import com.xintonghua.bussiness.api.manager.AuthManager;
import com.xintonghua.bussiness.bean.Auth;
import com.xintonghua.bussiness.ui.user.DianZhangTaskManageActivity;
import com.xintonghua.bussiness.ui.user.EvaluteManageActivity;
import com.xintonghua.bussiness.ui.user.GroupLogActivity;
import com.xintonghua.bussiness.ui.user.HistoryAcitivity;
import com.xintonghua.bussiness.ui.user.HomeManageActivity;
import com.xintonghua.bussiness.ui.user.MyRewardActivity;
import com.xintonghua.bussiness.ui.user.MyShareActivity;
import com.xintonghua.bussiness.ui.user.SettingActivity;
import com.xintonghua.bussiness.ui.user.ShareActivity;
import com.xintonghua.bussiness.ui.user.ShopManageActivity;
import com.xintonghua.bussiness.ui.user.StockOrderManageActivity;
import com.xintonghua.bussiness.ui.user.StorkStoreActivity;
import com.xintonghua.bussiness.ui.user.TaskManageActivity;
import com.xintonghua.bussiness.ui.user.UserInfoActivity;
import com.xintonghua.bussiness.util.GlideUtils;
import com.xintonghua.bussiness.util.JumpUtils;

import java.util.HashMap;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

/**
 * 作者：wanxianyi
 * 时间：2018/1/11.
 * 包名：com.xintonghua.bussiness.ui.fragment
 */

public class MyFragment extends BaseFragment {
    @BindView(R.id.tv_home_manage)
    TextView tvHomeManage;
    @BindView(R.id.tv_order_manage)
    TextView tvOrderManage;
    @BindView(R.id.tv_task_manage)
    TextView tvTaskManage;
    @BindView(R.id.tv_store_manage)
    TextView tvStoreManage;
    @BindView(R.id.tv_checking_in)
    TextView tvCheckingIn;
    @BindView(R.id.tv_my_share)
    TextView tvMyShare;
    @BindView(R.id.tv_share)
    TextView tvShare;
    @BindView(R.id.tv_my_reward)
    TextView tvMyReward;
    @BindView(R.id.tv_growup_log)
    TextView tvGrowupLog;
    @BindView(R.id.tv_my_stock_order_manage)
    TextView tvMyStockOrderManage;
    @BindView(R.id.tv_my_history_order)
    TextView tvMyHistoryOrder;
    @BindView(R.id.tv_stork_store)
    TextView tvStorkStore;
    Unbinder unbinder;
    @BindView(R.id.iv_head)
    ImageView ivHead;
    @BindView(R.id.tv_username)
    TextView tvUserName;
    @BindView(R.id.tv_phone)
    TextView tv_phone;

    @Override
    public int getLayout() {
        return R.layout.fragment_my;
    }

    @Override
    public void initUI(View rootView) {
        unbinder = ButterKnife.bind(this, rootView);
        Auth auth = AuthManager.geteAuth();
        if (auth != null) {
            tvUserName.setText(auth.getName());
            tv_phone.setText(auth.getPhone());
            GlideUtils.loadCricle(getActivity(), ivHead, auth.getImg());
        }
    }


    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }


    @OnClick({R.id.ll_head, R.id.tv_home_manage, R.id.tv_order_manage, R.id.tv_task_manage, R.id.tv_store_manage, R.id.tv_checking_in, R.id.tv_my_share, R.id.tv_share,
            R.id.tv_my_reward, R.id.tv_growup_log, R.id.tv_my_stock_order_manage, R.id.tv_my_history_order, R.id.tv_stork_store, R.id.iv_setting})
    public void onViewClicked(View view) {
        Bundle bundle;
        switch (view.getId()) {
            case R.id.ll_head:
                MyUtils.openActivity(getActivity(), UserInfoActivity.class);
                break;
            case R.id.tv_home_manage:
                if (!AuthManager.geteAuth().isIsBoss()) {
                    mToast("该功能只限店长使用");
                    return;
                }
                MyUtils.openActivity(getActivity(), HomeManageActivity.class);
                break;
            case R.id.tv_order_manage:
                MyUtils.openActivity(getActivity(), EvaluteManageActivity.class);
                break;
            case R.id.tv_task_manage:

                String position_id = AuthManager.geteAuth().getPosition_id();
                int id = AuthManager.geteAuth().getId();
                if (AuthManager.geteAuth().isIsBoss()) {//position_id为5说明是店长
                    MyUtils.openActivity(getActivity(), DianZhangTaskManageActivity.class);
                } else {
                    HashMap<String, String> map = new HashMap<>();
                    map.put("id", "" + id);
                    JumpUtils.jumpto(getActivity(), TaskManageActivity.class, map);
                }

                break;
            case R.id.tv_store_manage:
                MyUtils.openActivity(getActivity(), ShopManageActivity.class);
                break;
            //考情管理
            case R.id.tv_checking_in:
                if (!AuthManager.geteAuth().isIsBoss()) {
                    mToast("该功能只限店长使用");
                    return;
                }
                MyUtils.openActivity(getActivity(), QrCodeActiivity.class);
                break;
            //我的分享
            case R.id.tv_my_share:
                MyUtils.openActivity(getActivity(), MyShareActivity.class);
                break;
            //分享
            case R.id.tv_share:
                MyUtils.openActivity(getActivity(), ShareActivity.class);
                break;
            //我的打赏
            case R.id.tv_my_reward:
                MyUtils.openActivity(getActivity(), MyRewardActivity.class);
                break;
            //成长日志
            case R.id.tv_growup_log:
                MyUtils.openActivity(getActivity(), GroupLogActivity.class);
                break;
            case R.id.tv_my_stock_order_manage:
                MyUtils.openActivity(getActivity(), StockOrderManageActivity.class);
                break;
            case R.id.tv_my_history_order:
                MyUtils.openActivity(getActivity(), HistoryAcitivity.class);
                break;
            case R.id.tv_stork_store:
                MyUtils.openActivity(getActivity(), StorkStoreActivity.class);
                break;
            case R.id.iv_setting:
                MyUtils.openActivity(getActivity(), SettingActivity.class);
                break;
        }
    }
}
